package ro.cityprojects.adminloc.metadata;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static ro.cityprojects.adminloc.metadata.EntityMetadata.Details.build;
import static ro.cityprojects.adminloc.metadata.EntityMetadata.FieldTypes.*;

/**
 * Enumeration used to hold the metadata properties for each entity
 *
 * @author bogdan.solga
 */
@SuppressWarnings("unused")
public enum EntityMetadata implements Serializable {

    Person("Persons",
        build("id", "ID", number),
        build("firstName", "First Name", text),
        build("lastName", "Last Name", text),
        build("age", "Age", number),
        build("email", "Email", email),
        build("homePhoneNumber", "Home Phone Number", phone),
        build("userName", "User Name", text)
    ),

    Apartments("Apartments",
        build("id", "ID", number),
        /*
        build("entranceId", "Entrance", text),
        build("identifier", "Identifier", text),
        */
        build("alias", "Alias", text),
        build("numberOfPersons", "Number of Persons", number),
        build("surface", "Surface", number)
    ),

    Association("Associations",
        build("id", "ID", number),
        build("name", "Name", text),
        build("postalCode", "Postal Code", number)
    ),

    Street("Streets",
        build("id", "ID", number)
    ),

    Entrance("Entrances",
        build("id", "ID", number),
        build("name", "Name", text),
        build("apartmentsNumber", "Number of apartments", number)
    );

    private Map<String, Object> details;

    private EntityMetadata(String name, Details... details) {
        this.details = new HashMap<String, Object>();

        this.details.put("name", name);
        this.details.put("keys", Arrays.asList(details));
    }

    public Map<String, Object> getDetails() {
        return details;
    }

    protected static class Details {
        public String key;

        public String label;

        public String type;

        protected Details(String key, String label, String type) {
            this.key = key;
            this.label = label;
            this.type = type;
        }

        protected static Details build(String key, String label, FieldTypes type) {
            return new Details(key, label, type.name());
        }
    }

    protected static enum FieldTypes {
        text, number, email, phone
    }
}
